package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Gift;
import cn.wolfcode.crm.query.GiftQueryObject;
import cn.wolfcode.crm.service.IGiftService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("gift")
public class GiftController {

    @Autowired
    private IGiftService giftService;

    @RequestMapping("")
    public String index(){
        return "gift/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(GiftQueryObject qo){
        return giftService.query(qo);

    }
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Gift entity){

        try{
            giftService.save(entity);

        }catch(Exception e){
            e.printStackTrace();
            return new JsonResult("保存失败");
        }

        return new JsonResult();

    }
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(Gift entity){

        try{
            giftService.update(entity);

        }catch(Exception e){
            e.printStackTrace();
            return new JsonResult("修改失败");
        }
        System.out.println();


        return new JsonResult();

    }
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if(id != null){
        try{
            giftService.delete(id);

        }catch(Exception e){
            e.printStackTrace();
            return new JsonResult("删除失败");
        }
        }

        return new JsonResult();

    }

    @RequestMapping("pointsChange")
    public String change(){
        return "gift/pointsChange";
    }





}
